package com.shushan.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.shushan.home.bean.TodayRecordBean;
import com.shushan.shushanbao.R;

import java.util.List;

/**
 * @ClassName: TodayRecordAdapter
 * @Desciption: 今日练习记录Adapter
 * @author: yichaohua
 * @date: 2018-07-20
 */
public class TodayRecordAdapter extends BaseAdapter {

    private Context context;
    List<TodayRecordBean> todayRecordBeanList;

    public TodayRecordAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        if(todayRecordBeanList == null){
            return 0;
        }else {
            return todayRecordBeanList.size();
        }

    }

    @Override
    public Object getItem(int position) {
        if(todayRecordBeanList == null){
            return null;
        }else {
            return todayRecordBeanList.get(position);
        }

    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (null == convertView) {
            //填充布局
            convertView =  LayoutInflater.from(context).inflate(R.layout.today_record_list_item, parent,false);
            holder = new ViewHolder();
            //通过ID查询控件
            holder.dateTextView = convertView.findViewById(R.id.today_record_item_date_tv);
            holder.timeTextView = convertView.findViewById(R.id.today_record_item_time_tv);
            holder.rightTextView = convertView.findViewById(R.id.today_record_item_right_tv);
            holder.totalTextView = convertView.findViewById(R.id.today_record_item_total_tv);
            holder.scoreTextView = convertView.findViewById(R.id.today_record_item_score_tv);

            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        TodayRecordBean TodayRecordBean = todayRecordBeanList.get(position);
        holder.dateTextView.setText(TodayRecordBean.year);
        holder.timeTextView.setText(TodayRecordBean.time);
        holder.rightTextView.setText(TodayRecordBean.right_count + "");
        holder.totalTextView.setText("/" + TodayRecordBean.exercises_count);
        holder.scoreTextView.setText(TodayRecordBean.score + "分");

        return convertView;
    }

    public static class ViewHolder{
        TextView dateTextView;
        TextView timeTextView;
        TextView rightTextView;
        TextView totalTextView;
        TextView scoreTextView;
    }

    public List<TodayRecordBean> getTodayRecordBeanList() {
        return todayRecordBeanList;
    }

    public void setTodayRecordBeanList(List<TodayRecordBean> todayRecordBeanList) {
        this.todayRecordBeanList = todayRecordBeanList;
    }
}
